import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:flutter_wan_android/arch/ui/loading.dart';
import 'package:flutter_wan_android/page/system_navi.dart';
import 'package:flutter_wan_android/page/system_tx.dart';
import 'package:flutter_wan_android/widget/wan_appbar.dart';
import 'package:flutter_wan_android/res/theme.dart';

class SystemPage extends StatefulWidget {
  @override
  _SystemPageState createState() => _SystemPageState();
}

class _SystemPageState extends State<SystemPage> {
  late SwiperController _controller = SwiperController();

  int _currentPage = 0;

  var _pages = [SystemTixi(), SystemNavi()];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _getHead(),
      backgroundColor: context.wTheme.background,
      body: Swiper(
        controller: _controller,
        itemBuilder: (BuildContext context, int index) {
          return _pages[index];
        },
        itemCount: 2,
        loop: false,
        onIndexChanged: (index) {
          setState(() {
            _currentPage = index;
          });
        },
      ),
    );
  }

  _getHead() {
    return WanAppbar(context,
        title: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            GestureDetector(
              onTap: () {
                _changePage(0);
              },
              child: Text(
                "体系",
                style: _getTitleStyle(0),
              ),
            ),
            Padding(padding: EdgeInsets.only(left: 15)),
            GestureDetector(
              onTap: () {
                _changePage(1);
              },
              child: Text(
                "导航",
                style: _getTitleStyle(1),
              ),
            )
          ],
        ));
  }

  _changePage(int index) {
    setState(() {
      LoadingUtil.hide();
      _currentPage = index;
      _controller.move(_currentPage);
    });
  }

  _getTitleStyle(int index) {
    if (index == _currentPage) {
      return TextStyle(fontSize: 18, color: Color(0xFFFFFFFF));
    } else {
      return TextStyle(fontSize: 18, color: Color(0x88FFFFFF));
    }
  }
}
